package com.ziq.zcamp.place

import android.content.Context
import com.donkingliang.groupedadapter.adapter.GroupedRecyclerViewAdapter
import com.donkingliang.groupedadapter.holder.BaseViewHolder
import com.ziq.zcamp.R
import com.ziq.zcamp.bean.place.DetailGroup
import com.ziq.zcamp.bean.place.VrInfo
import com.ziq.zcamp.bean.post.ImageInfo

class PlaceDetailBannerAdapter(context: Context) : GroupedRecyclerViewAdapter(context) {

    companion object {
        const val TYPE_VR = 1
        const val TYPE_IMAGE = 2
    }

    var groupList: MutableList<DetailGroup> = mutableListOf()
    var bannerGroup = PlaceDetailBannerGroup(this)

    var onImagePageChangeCallback: ((position:Int, size:Int)->Unit)? = null
    var onVrClickCallback: ((vr: VrInfo)->Unit)? = null

    init {
        groupList.add(bannerGroup)
    }


    fun setBannerData(imageList: MutableList<ImageInfo>?, vr:VrInfo?) {
        bannerGroup.setBannerData(imageList, vr)
        notifyDataSetChanged()
    }

    override fun getGroupCount(): Int {
        return groupList.size
    }

    override fun getChildrenCount(groupPosition: Int): Int {
        return groupList.get(groupPosition).getChildrenCount()
    }

    override fun hasHeader(groupPosition: Int): Boolean {
        return groupList[groupPosition].hasHeader(groupPosition)
    }

    override fun hasFooter(groupPosition: Int): Boolean {
        return groupList[groupPosition].hasFooter(groupPosition)
    }

    override fun getHeaderViewType(groupPosition: Int): Int {
        return groupList[groupPosition].getHeaderViewType(groupPosition)
    }

    override fun getChildViewType(groupPosition: Int, childPosition: Int): Int {
        return groupList[groupPosition].getChildViewType(groupPosition, childPosition)
    }

    override fun getHeaderLayout(viewType: Int): Int {
        return 0
    }

    override fun getFooterLayout(viewType: Int): Int {
        return 0
    }

    override fun getChildLayout(viewType: Int): Int {
        return when (viewType) {
            TYPE_VR -> {
                R.layout.item_place_detail_banner_vr
            }
            TYPE_IMAGE -> {
                R.layout.item_place_detail_banner_image
            }
            else -> {
                0
            }
        }
    }

    override fun onBindHeaderViewHolder(holder: BaseViewHolder?, groupPosition: Int) {
        groupList[groupPosition].onBindHeaderViewHolder(holder, groupPosition)
    }

    override fun onBindFooterViewHolder(holder: BaseViewHolder?, groupPosition: Int) {
        groupList[groupPosition].onBindFooterViewHolder(holder, groupPosition)

    }

    override fun onBindChildViewHolder(
        holder: BaseViewHolder?,
        groupPosition: Int,
        childPosition: Int
    ) {
        groupList[groupPosition].onBindChildViewHolder( holder, groupPosition, childPosition)
    }


}
